//app.js
require('./envconfigs')()

App({
  onLaunch: function () {
    const {options} = wx.CONFIG.env

    // 是否初始化云端开发
    if (options.cloud) {
      if (!wx.cloud) {
        console.error('请使用 2.2.3 或以上的基础库以使用云能力')
      } else {
        wx.cloud.init({ traceUser: true })
        wx.isCloud = true
      }
    }
    

    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
        }
      }
    }) //系统信息
    wx.getSystemInfo({
      success: (res) => {
        const menuButtonObject = wx.getMenuButtonBoundingClientRect();
        const { top, height } = menuButtonObject;
        this.globalData.statusBarHeight = res.statusBarHeight
        this.globalData.navheight = res.statusBarHeight + height + (top - res.statusBarHeight) * 2;
        this.globalData.menuButtonHeight = height
        this.globalData.screenWidth = res.screenWidth
        // this.globalData.navheight = navBarHeight
      }
    })
  },
  globalAd: '',
  globalData: {
    userInfo: null,
    navheight: 23,
    menuButtonHeight: null,
    screenWidth: 375,
    openid: null
  },
})